<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Models\User;
use Illuminate\Support\Facades\Log;

class ResetUserPassword extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'reset_user:password {phone} {password}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '修改一个后台用户的密码';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $phone = $this->argument('phone');
        $password = $this->argument('password');
        Log::info("修改用户密码{$phone},{$password}");
        $user = User::wherePhone($phone)->first();
        if(!$user){
            Log::error('用户'.$phone.'不存在!');
            return 0;
        }
        $user->password = bcrypt($password);
        $user->save();
        Log::info("修改用户密码成功{$phone},{$password}");
    }
}
